JavaScript

The scripting language of the web

JavaScript Overview

JavaScript (often abbreviated as JS) is a lightweight, interpreted, object-oriented language with first-class functions, most known as the scripting language for Web pages, but used in many non-browser environments as well.

Paradigm

Multi-paradigm: event-driven, functional, imperative, object-oriented

Designed by

Brendan Eich

First appeared

1995

Stable release

ECMAScript 2022

Key Features

Common Use Cases

Web Development

Essential for creating interactive and dynamic web pages.

Frontend Frameworks

Used with React, Angular, Vue.js for building complex user interfaces.

Server-side Development

Node.js allows JavaScript to be used for backend development.

Mobile Apps

Frameworks like React Native enable cross-platform mobile development.

Example Code

// Modern JavaScript (ES6+) example

// Arrow functions
const greet = (name) => {
    return `Hello, ${name}! Welcome to JavaScript.`;
};

// Class syntax
class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
    
    introduce() {
        return `Hi, I'm ${this.name} and I'm ${this.age} years old.`;
    }
}

// Async/await example
async function fetchData(url) {
    try {
        const response = await fetch(url);
        const data = await response.json();
        console.log(data);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}

// Using the examples
console.log(greet('Alice'));

const alice = new Person('Alice', 30);
console.log(alice.introduce());

fetchData('https://api.example.com/data');

Learning Resources